package com.qf.config;

import com.qf.dao.OrderRepository;
import com.qf.pojo.vo.QfOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class PaySchedule {

    @Autowired
    OrderRepository orderRepository;

    private static Logger logger = LoggerFactory.getLogger(PaySchedule.class);
    //@Scheduled(cron = "0/10 * * * * ?")
    public void payEndTime(){
        logger.debug("====进入了定时任务===");
        List<QfOrder> byEndTimeAfterAndOrderStatus = orderRepository.findByEndTimeAfterAndOrderStatus(new Date(), 3);
        if (byEndTimeAfterAndOrderStatus!=null&&byEndTimeAfterAndOrderStatus.size()>0){
            //如果获取到 则代表，改笔订单到时间未支付，则置为取消支付
            for (QfOrder qf :byEndTimeAfterAndOrderStatus
                 ) {
                qf.setOrderStatus(4);
                logger.debug("====查询出的订单为：==="+byEndTimeAfterAndOrderStatus);
                orderRepository.saveAndFlush(qf);
            }

        }

    }
}
